<?php
//后台管理员模块的ACTION
class CenterAction extends BaseAction {
	
	//密码修改
	public function changepwd(){
		$referUrl = $_SERVER['HTTP_REFERER'];
		$this->assign("referUrl",$referUrl);
		$this->display();
	}
	
	//密码修改的处理流
	public function changepwd_process(){
		$oldPwd = $this->_post("oldPwd");
		$newPwd = $this->_post("newPwd");
		$pwd4confirm = $this->_post("pwd4confirm");
		if($newPwd != $pwd4confirm){
			echo CommonUtil::ajaxReturn(Status::$ERROR, "新密码和确认密码不相同，请重新输入！");
			return;
		}
	    if(!ValidateUtil::isAvailableLength($newPwd,6,18)){
            echo CommonUtil::ajaxReturn(Status::$ERROR, "密码长度为6～18个字符!");
            return;
        }
		$adminName = $_SESSION["admin"]["admin_name"];
		$result = AdminHelper::checkLogin( $adminName, $oldPwd );
		if ($result != "true") {	//旧密码输入失败，提示对应的错误信息
			echo CommonUtil::ajaxReturn(Status::$ERROR, $result);
			return;
		}
		$salt = CommonUtil::generateStr(4);
		$result = AdminHelper::updatePWD($adminName,$newPwd,$salt);
		if($result <= 0){
			echo CommonUtil::ajaxReturn(Status::$ERROR, "服务器繁忙！请稍后重试！");
			return;
		}
		echo CommonUtil::ajaxReturn(Status::$SUCCESS, "密码修改成功！");
	}
	
	//注销
	public function logout(){
		session('admin',null);
		redirect(__APP__."/center/login/");
	}
	
}